define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/withdrawal_merchant/index' + location.search,
                    add_url: 'finance/withdrawal_merchant/add',
                    // edit_url: 'finance/withdrawal_merchant/edit',
                    // del_url: 'finance/withdrawal_merchant/del',
                    multi_url: 'finance/withdrawal_merchant/multi',
                    import_url: 'finance/withdrawal_merchant/import',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: '商家id'},
                        {field: 'user.nickname', title: '用户昵称'},
                        {field: 'card_no', title: '手机号'},
                        {field: 'log_mod', title: '提现方式'},
                        {field: 'wallet', title: '提现金额'},
                        {field: 'before_wallet', title: '提现前金额'},
                        {field: 'after_wallet', title: '提现后金额'},
                        {field: 'real_name', title: '真实姓名'},
                        {field: 'qrcode_image', title: '所属业务员', operate: false},
                        {field: 'user.area', title: '区域'},
                        {field: 'batch_id', title: '第三方单号'},
                        {field: 'log_status', title: __('Status'),searchList: {"0": "审核中", "1": "通过", "-1":"不通过", "2":"微信转账中"}, formatter: Table.api.formatter.status},
                        {field: 'handel_desc', title: '驳回原因'},
                        {field: 'handel_admin_id', title: '操作管理员', operate: false},
                        {field: 'create_dt', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_dt', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        {
                            field: "operate",
                            title: __("Operate"),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: "agree",
                                title: "审核通过",
                                classname: "btn btn-xs btn-success btn-magic btn-ajax",
                                icon: "fa fa-check",
                                text: "同意",
                                confirm: "确认点击同意，通过审核？",
                                url: "finance/withdrawal_merchant/agree",
                                visible: function(row){
                                    if ("0" == row.log_status) return ! 0
                                }, 
                                refresh: true
                            },
                            {
                                name: "refuse",
                                title: __("审核不通过"),
                                classname: "btn btn-xs btn-danger btn-dialog",
                                icon: "fa fa-times",
                                text: "拒绝",
                                url: "finance/withdrawal_merchant/refuse",
                                extend: 'data-area=["500px","270px"]',
                                visible: function(row){
                                    if ("0" == row.log_status) return ! 0
                                }, 
                                refresh: true,
                            },
                            // {
                            //     name: "edit",
                            //     text: __("详情"),
                            //     classname: "btn btn-xs btn-info btn-dialog",
                            //     icon: "fa fa-eye",
                            //     url: "finance/withdrawal_merchant/edit"
                            // },
                            // {
                            //     name: 'del',
                            //     text: '删除',
                            //     icon: 'fa fa-trash',
                            //     classname: 'btn btn-xs btn-danger btn-delone',
                            //     url: 'finance/withdrawal_merchant/del'
                            // },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'finance/withdrawal_merchant/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_name', title: '店铺名称', align: 'left'},
                        {
                            field: 'delete_dt',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'finance/withdrawal_merchant/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'finance/withdrawal_merchant/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
